﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator;
using EuroManager.Services.Data;

namespace EuroManager.Services.Implementation
{
    public class SimulatorService : ISimulatorService
    {
        public GameData Play()
        {
            var simulator = new GameSimulator(new GameWorldFactory(TimeSpan.FromMinutes(5)));
            var result = simulator.Play();

            return new GameData
            {
                FrameCount = result.FrameCount,
                Fps = result.Fps,
                BallFps = result.BallFps,
                PlayerFps = result.PlayerFps,
                Score1 = result.Score1,
                Score2 = result.Score2,
                TimeUpdates = result.TimeUpdates,
                Score1Updates = result.Score1Updates,
                Score2Updates = result.Score2Updates,
                Ball = new BallData
                {
                    X = result.Ball.X,
                    Y = result.Ball.Y
                },
                Players = result.Players.Select(p =>
                    new PlayerData
                    {
                        Team = p.Team == Domain.Simulator.Result.GameTeam.Team1 ? GameTeam.Team1 : GameTeam.Team2,
                        Number = p.Number,
                        X = p.X,
                        Y = p.Y,
                        Angle = p.Angle
                    }).ToArray(),
                Highlights = result.Highlights.Select(h =>
                    new HighlightData
                    {
                        StartFrame = h.StartFrame,
                        EndFrame = h.EndFrame
                    }).ToArray()
            };
        }
    }
}
